<template>
    <div>
        <el-form :inline="true" :model="query" class="query-form" size="small">
            <el-form-item>
                <el-button type="primary" icon="el-icon-edit" @click.native="handleForm(null,null)">添加</el-button>
            </el-form-item>

            <el-form-item>
                <el-input v-model="query.bannetitle" placeholder="请输入图片标题" clearable></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-refresh" @click="onRest"></el-button>
                <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
            </el-form-item>
        </el-form>

        <el-table
            ref="multipleTable"
            v-loading="loading"
            :data="list"
            :header-cell-style="{background:'#F4F4F5',color:'#606266'}"
            @selection-change="handleSelectionChange"
            border
        >
            <!--  <el-table-column
                  label="选择"
                  prop="bannerid"
                  type="selection"
                  :show-overflow-tooltip="true"
                  width="50"
                  align="center"
              />-->
            <el-table-column type="selection" width="50" fixed/>
            <el-table-column label="序号" align="center" width="50" prop="bannerid">
            </el-table-column>

            <el-table-column label="轮播图" prop="bannepicture" align="center" width="180">
                <template slot-scope="scope">
                    <el-popover v-if="scope.row.bannepicture" placement="right" trigger="hover">
                        <img :src="scope.row.bannepicture" style="width:400px;border-radius:3px;">
                        <img
                            slot="reference"
                            :src="scope.row.bannepicture"
                            style="max-height: 80px;max-width: 50px;border-radius:5px;"
                        >
                    </el-popover>
                    <span v-else>-</span>
                </template>
            </el-table-column>

            <el-table-column label="标题" align="center" width="180" prop="bannetitle">
            </el-table-column>
            <el-table-column label="跳转目标" align="center" width="180" prop="bannejumptype">
                <template  slot-scope="scope" >
                    <!--    <span>{{scope.row.bannejumptype}}</span>-->
                    <div v-if="scope.row.bannejumptype==='0'">
                        <span>{{scope.row.banneurl}}</span>
                    </div>
                    <div v-if="scope.row.bannejumptype==='1'">
                        <span>{{scope.row.commodityname}}</span>
                    </div>
                    <div v-if="scope.row.bannejumptype==='2'">
                        <span>{{scope.row.categoryname}}</span>
                    </div>

                </template>

            </el-table-column>


            <el-table-column label="排序" align="center" width="180" prop="bannersort">
            </el-table-column>
            <el-table-column label="上线时间" align="center" width="180" prop="bannejumptype">

                <template slot-scope="scope">
                    <i class="el-icon-time" v-if="scope.row.takeeffecttime!=null"></i>
                    <span
                        v-if="scope.row.takeeffecttime!=null"
                    >{{ scope.row.takeeffecttime | formatDateStr('yyyy-MM-dd hh:mm:ss') }}</span>

                </template>

            </el-table-column>

            <el-table-column label="下线时间："  width="180" style="margin-left:80px; width:30%;display: inline-block;">

                <template slot-scope="scope">
                    <i class="el-icon-time" v-if="scope.row.invalidtime!=null"></i>
                    <span
                        v-if="scope.row.invalidtime!=null"
                    >{{ scope.row.invalidtime | formatDateStr('yyyy-MM-dd hh:mm:ss') }}</span>

                </template>
            </el-table-column>
            <el-table-column label="状态" prop="banneswitch" align="center" width="180">
                <template slot-scope="scope">
                    <span>{{ scope.row.banneswitch==0?'开启':'关闭'}}    </span>
                    <el-switch
                        v-model="scope.row.banneswitch"
                        active-color="#13ce66"
                        inactive-color="#ff4949"
                        active-value="0"
                        inactive-value="1"
                        @change="swithchange(scope.row)"
                    >
                    </el-switch>
                </template>

            </el-table-column>


            <el-table-column  label="操作" align="center" >
                <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click.native="handleLook(scope.$index,scope.row)">查看</el-button>
                    <el-button type="primary" size="mini" @click.native="handleForm(scope.$index,scope.row)">编辑</el-button>
                    <el-button type="danger" size="mini" @click.native="handleDel(scope.row.bannerid)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="left-container">
            <el-button type="danger" size="small" @click="delGroup()">删除已选</el-button>
            <transition name="el-fade-in-linear">
                <el-button size="small" @click="toggleSelection()" v-show="cancelToggle">取消选择</el-button>
            </transition>
        </div>
        <el-pagination
            class="pagination-container"
            background
            :page-size="query.pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total,sizes,prev, pager, next, jumper"
            :page-sizes="[10, 20, 30, 50]"
            :total="totalNumber"
        ></el-pagination>

        <!--查看弹框-->
        <el-dialog
            :title="formMap[formName]"
            :visible.sync="detailVisible"
            :before-close="hideDetailForm"
            width="700px"
            top="5vh"
            v-dialogDrag
        >
            <el-form :model="formData" label-width="140px">
                <el-form-item  style="border-bottom:1px solid #ebeef5;" label-width="0px">
                    <el-form-item label="注册时间：" style=" width:50%;display: inline-block;">
                        <input
                            :value="formData.banneaddtime |formatDateStr('yyyy-MM-dd') "
                            type="text"
                            readonly
                        >
                    </el-form-item>
                    <el-form-item label="" style=" width:50%;display: inline-block;">
                    </el-form-item>
                </el-form-item>

                <el-form-item  style="border-bottom:1px solid #ebeef5;" label-width="0px">
                    <el-form-item label="标题：" style=" width:30%;display: inline-block;">
                        <input v-model="formData.bannetitle" type="text" readonly>
                    </el-form-item>
                    <el-form-item label="" style=" width:30%;display: inline-block;">

                    </el-form-item>
                </el-form-item>

                <el-form-item  style="border-bottom:1px solid #ebeef5;" label-width="0px">
                    <el-form-item label="跳转目标："  style=" width:30%;display: inline-block;">
                        <input v-model="formData.banneurl" type="text" readonly>
                    </el-form-item>
                    <el-form-item label="" style=" width:30%;display: inline-block;">

                    </el-form-item>
                </el-form-item>
                <el-form-item style="border-bottom:1px solid #ebeef5;"  label-width="0px">

                    <el-form-item label="上线时间：" style="width:30%;display: inline-block;">
                        <!-- <input v-model="formData.takeeffecttime" type="text" readonly>-->
                        <input
                            :value="formData.takeeffecttime |formatDateStr('yyyy-MM-dd') "
                            type="text"
                            readonly
                        >
                    </el-form-item>
                    <el-form-item label="下线时间：" style="margin-left:80px; width:30%;display: inline-block;border-bottom:1px solid #ebeef5;">
                        <!--  <input v-model="formData.invalidtime" type="text" readonly>-->
                        <input
                            :value="formData.invalidtime |formatDateStr('yyyy-MM-dd') "
                            type="text"
                            readonly
                        >
                    </el-form-item>

                </el-form-item>

                <el-form-item style="border-bottom:1px solid #ebeef5;"  label-width="0px">
                    <el-form-item label="排序：" style="width:30%;display: inline-block;">
                        <input v-model="formData.bannerid" type="text" readonly>
                    </el-form-item>
                    <el-form-item label="启用状态：" style=" margin-left: 80px; width:30%;display: inline-block;">
                        <!-- <input v-model="formData.banneswitch" type="text" readonly>-->
                        <template slot-scope="scope">
                            <span>{{ formData.banneswitch==0?'是':'否'}}</span>
                        </template>
                    </el-form-item>
                </el-form-item>

                <el-form-item label="轮播图："  style="width:80%;display: inline-block">

                    <el-popover v-if="formData.bannepicture" placement="right" trigger="hover" >
                        <img :src="formData.bannepicture" style="width:800px;border-radius:3px;">
                        <img
                            slot="reference"
                            :src="formData.bannepicture"
                            style="max-height: 400px;max-width: 400px;border-radius:5px;"
                        >
                    </el-popover>
                    <span v-else>-</span>

                </el-form-item>

            </el-form>

        </el-dialog>

        <!-- </el-scrollbar> -->
        <!--add表单-->
        <el-dialog
            :title="formMap[formName]"
            :visible.sync="formVisible"
            :before-close="hideForm"
            width="800px"
            top="5vh"
            v-dialogDrag
        >
            <el-form :model="formData" :rules="formRules" ref="dataForm" >
                <el-form-item label="添加标题:" prop="bannetitle" >
                    <el-input v-model="formData.bannetitle" placeholder="请输入添加标题名称" clearable></el-input>
                </el-form-item>
                <el-form-item >
                    <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
                    <el-upload
                        class="upload-demo"
                        :action="uploadUrl"
                        :on-change="handleChange"
                        multiple
                        :on-success="handleSuccess"

                        :file-list="uploadData"
                    >  <!-- :data="uploadData"-->
                        <el-button size="small" type="primary">点击上传</el-button>
                    </el-upload>

                </el-form-item>
                <el-form-item label="选择开启结束时间">
                    <el-date-picker
                        v-model="createTime"
                        type="datetimerange"
                        :picker-options="pickerOptions"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        align="left"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        :default-time="['00:00:00','23:59:59']"
                        @change="dateChange"
                    ></el-date-picker>
                </el-form-item>

                <el-form-item label="序号:" prop="bannersort" style="width:40%;display: inline-block;margin-left: 20px" label-width="80px">
                    <el-input v-model="formData.bannersort" placeholder="请输入序号" type= "number" clearable></el-input>
                </el-form-item>

                <el-form-item label="跳转目标:"  style="width:40%;">
                    <el-select v-model="formData.bannejumptype"  placeholder="请选择" @change="selectchange(formData.bannejumptype)"
                               clearable>
                        <el-option label="链接" value='0'></el-option>
                        <el-option label="商品" value='1'></el-option>
                        <el-option label="分类" value='2'></el-option>
                    </el-select>

                </el-form-item>
                <!--跳转目标-->
                <el-form-item>

                    <el-form-item label="商品" v-if="formData.bannejumptype==='0'">
                        <el-input v-model="formData.banneurl" placeholder="请输入链接" clearable></el-input>
                    </el-form-item>

                    <el-form-item label="商品" v-if="formData.bannejumptype==='1'">
                        <!-- <label >{{formData}}</label>-->
                        <!--  <el-input v-model="formData.commodityid" aria-readonly="true" clearable></el-input>-->
                        <input readonly="ture" v-model="commodityname"/>

                    </el-form-item>

                    <div v-if="formData.bannejumptype==='2'">

                        <el-form-item  label="一级分类">
                            <!--<el-select v-model="query.topcategoryid"  placeholder="请选择" :onchange="topchange()">-->
                            <el-select v-model="formData.topcategoryid"  placeholder="请选择" @change="topchange()">
                                <el-option
                                    v-for="(item,index) in category"
                                    :key="index"
                                    :label="item.topcategoryname"
                                    :value="item.topcategoryid">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item  label="二级分类">
                            <el-select v-model="formData.secondarycategoryid"  placeholder="请选择" clearable @change="secondchange()">
                                <el-option
                                    v-for="(item,index) in busCommoditySecondaryCategoryList"
                                    :key="index"
                                    :label="item.secondarycategoryname"
                                    :value="item.secondarycategoryid">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="三级分类">
                            <el-select v-model="formData.thirdcategoryid"  placeholder="请选择" clearable @change="thirdchange()">
                                <el-option
                                    v-for="(item,index) in busCommodityThirdCategoryList"
                                    :key="index"
                                    :label="item.thirdcategoryname"
                                    :value="item.thirdcategoryid">
                                </el-option>
                            </el-select>
                        </el-form-item>

                    </div>
                </el-form-item>

                <el-form-item>
                    <template>
                        <el-radio v-model="formData.banneswitch" label="0">启动</el-radio>
                        <el-radio v-model="formData.banneswitch" label="1">关闭</el-radio>
                    </template>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="hideForm">取消</el-button>
                <el-button type="primary" @click.native="formSubmit()" :loading="formLoading">提交</el-button>
            </div>
        </el-dialog>

        <el-dialog
            :title="formMap[formName]"
            :visible.sync="dialogVisiblesssss"
            :close-on-click-modal="false"
            width="1000px"
            top="5vh"
            v-dialogDrag>
            <div>
                <getGoods @on-select="selectids" ></getGoods>
            </div>
        </el-dialog>

    </div>
</template>

<script>
    import {
        getList,
        delRotaryPlanting,
        updateBusCommodityBanner,
        addRotaryPlanting,
        getCategory
    } from "../../api/rotaryplantingmap/rotaryPlantingMap.js";
    import { BASE_URL } from "../../config/app";
    import getGoods from "../../components/goods/getGoods.vue";

    const formJson = {
        bannerid: "", //id
        bannetitle: "", //标题
        banneurl: "", //跳转目标
        takeeffecttime: "", //上线时间
        invalidtime: "", //下线时间
        banneswitch: "1", //启用
        bannepicture: "", //轮播图
        bannersort: 0, //排序
        commodityid: 0, //商品
        categoryid: "",
        topcategoryid: "", //一级
        secondarycategoryid: "", //二级
        thirdcategoryid: "", //三级
        bannejumptype: "", //跳转类型  0  跳转链接  1 商品  2 分类
        categorylevl: 0 //1 一级分类 2 二级分类 1 三级分类
    };
    export default {
        name: "rotaryPlantingMap",
        components: {
            getGoods
        },
        filters: {
            formatDate: function(value) {
                let date = new Date(value);
                let y = date.getFullYear();
                let MM = date.getMonth() + 1;
                MM = MM < 10 ? "0" + MM : MM;
                let d = date.getDate();
                d = d < 10 ? "0" + d : d;
                let h = date.getHours();
                h = h < 10 ? "0" + h : h;
                let m = date.getMinutes();
                m = m < 10 ? "0" + m : m;
                let s = date.getSeconds();
                s = s < 10 ? "0" + s : s;
                return y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
            }
        },
        data() {
            return {
                pickerOptions: {
                    //快速选择日期
                    shortcuts: [
                        {
                            text: "最近一周",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 7
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        },
                        {
                            text: "最近一个月",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 30
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        },
                        {
                            text: "最近三个月",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 90
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        },
                        {
                            text: "最近六个月",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 180
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        }
                    ]
                },

                uploadUrl: BASE_URL + '/goldendays-currency/tool/uploadpro', //上传图片
                uploadData: [],
                cancelToggle: false,
                createTime: [],
                query: {
                    startTime: "",
                    endTime: "",
                    bannerid: "",
                    bannetitle: "", //仓库名
                    currentPage: 1,
                    pageSize: 10
                },
                commodityname: "无", //商品名
                list: [],
                totalNumber: 0,
                loading: true,
                index: null,
                formName: "",
                formMap: {
                    add: "添加",
                    edit: "编辑",
                    look: "查看",
                    seluser: "选择用户"
                },
                category: [], //分类列表
                busCommoditySecondaryCategoryList: [], //二级
                busCommodityThirdCategoryList: [], //三级
                mcategoryid: "",
                dialogVisiblesssss: false,
                detailVisible: false,
                dialogVisible: false,
                formLoading: false,
                formVisible: false,
                editshow: false,
                formData: formJson,
                formRules: {
                    bannetitle: {
                        required: true,
                        message: "请输入名称",
                        trigger: "blur"
                    },
                    bannersort: {
                        required: true,
                        message: "请输入序号",
                        trigger: "blur"
                    }
                },
                multipleSelection: [], //多选集合
                uploadAction: BASE_URL + "/systemSetup/import"
            };
        },

        methods: {
            //选择用户
            selectids(ids, v, name) {
                this.dialogVisiblesssss = v;
                this.formData.commodityid = ids;
                this.commodityname = name;
            },
            handleSuccess(response, file) {
                this.isSelect = false;
                console.log("上传成功");
                if (response.status === 1) {
                    const filePath = response.data;
                    this.formData.bannepicture = filePath;
                    console.info(filePath + file);
                    return;
                }

                this.$message.error("上传文件报错");
            },
            handleChange(file, fileList) {
                this.uploadData = [fileList[fileList.length - 1]]; // 覆盖
                this.fileName = file.name ? file.name : "";
                return false;
            },
            //开关
            swithchange(row) {
                if (row !== null) {
                    var params = new URLSearchParams();
                    params.append("bannerid", row.bannerid);
                    params.append("banneswitch", row.banneswitch);
                    updateBusCommodityBanner(params).then(response => {
                        this.formLoading = false;
                        if (response.code != 0) {
                            this.$message.error(response.message);
                            return false;
                        }
                        this.$message.success("操作成功");
                    });
                }
            },
            //选择类型
            selectchange(val) {
                console.info(val);
                if (val === "1") {
                    //alert(val);
                    console.info(111111111);
                    // this.commodityid=val;
                    this.dialogVisiblesssss = true;
                    this.formName = "seluser";
                }
                if (val === "2") {
                    this.getAllCategory();
                }
            },

            //查看详情
            handleLook(index, row) {
                this.detailVisible = true;
                this.formData = Object.assign({}, formJson);
                if (row !== null) {
                    this.formData = Object.assign({}, row);
                    this.formName = "look";
                }
            },
            // 隐藏详情弹框
            hideDetailForm() {
                // 更改值
                this.detailVisible = !this.detailVisible;
                return true;
            },

            before() {
                this.loading = this.$loading({
                    lock: true,
                    text: "Loading",
                    spinner: "el-icon-loading",
                    background: "rgba(0, 0, 0, 0.7)"
                });
            },

            dateChange(val) {
                if (val == null) {
                    this.formData.takeeffecttime = "";
                    this.formData.invalidtime = "";
                } else {
                    this.formData.takeeffecttime = val[0];
                    this.formData.invalidtime = val[1];
                }
            },
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
                if (val == "") {
                    this.cancelToggle = false;
                    return;
                }
                this.cancelToggle = true;
            },
            delGroup() {
                var ids = this.multipleSelection.map(item => item.bannerid).join(); //获取所有选中行的id组成的字符串，以逗号分隔
                if (ids == "") {
                    this.$message({
                        message: "请先选择",
                        type: "warning"
                    });
                    return;
                }
                this.handleDel(ids);
            },
            onRest() {
                this.$router.push({
                    path: ""
                });
                this.query = {
                    currentPage: 1,
                    pageSize: 10
                };
                this.createTime = [];
                this.getList();
            },
            onSubmit() {
                this.$router.push({
                    path: "",
                    query: this.query
                });
                this.getList();
            },
            handleCurrentChange(val) {
                this.query.currentPage = val;
                //scrollTo(0, 800);
                this.getList();
            },
            handleSizeChange(val) {
                this.query.pageSize = val;
                this.getList();
            },
            getList() {
                this.loading = true;
                getList(this.query)
                    .then(response => {
                        if (response.code) {
                            this.$message.error(response.message);
                        }
                        this.list = response.data.list || [];
                        if (this.list.length > 0) {
                            let mylist = this.list;
                            for (var i = 0; i < mylist.length; i++) {
                                if (mylist[i].banneswitch != null) {
                                    mylist[i].banneswitch = mylist[
                                        i
                                        ].banneswitch.toString();
                                    mylist[i].bannejumptype = mylist[
                                        i
                                        ].bannejumptype.toString();
                                }
                            }
                            this.list = mylist;
                        }

                        //this.list = response.data.list || [];
                        this.totalNumber = response.data.totalNumber || 0;
                        setTimeout(() => {
                            this.loading = false;
                        }, 0.3 * 1000);
                    })
                    .catch(() => {
                        this.loading = false;
                        this.list = [];
                        this.totalNumber = 0;
                    });
            },

            //一级
            topchange() {
                for (var i = 0; i < this.category.length; i++) {
                    if (
                        this.category[i].topcategoryid ==
                        this.formData.topcategoryid
                    ) {
                        this.busCommoditySecondaryCategoryList = this.category[
                            i
                            ].busCommoditySecondaryCategoryList;
                        if (
                            this.category[i].topcategoryid ===
                            this.formData.topcategoryid
                        ) {
                            this.formData.categorylevl = 1;
                            this.formData.categoryid = this.formData.topcategoryid;
                        }

                        break;
                    }
                }
            },
            //二级
            secondchange() {
                for (
                    var i = 0;
                    i < this.busCommoditySecondaryCategoryList.length;
                    i++
                ) {
                    if (
                        this.busCommoditySecondaryCategoryList[i]
                            .secondarycategoryid ==
                        this.formData.secondarycategoryid
                    ) {
                        this.busCommodityThirdCategoryList = this.busCommoditySecondaryCategoryList[
                            i
                            ].busCommodityThirdCategoryList;
                        if (
                            this.busCommoditySecondaryCategoryList[i]
                                .secondarycategoryid ===
                            this.formData.secondarycategoryid
                        ) {
                            this.formData.categorylevl = 2;
                            this.formData.categoryid = this.formData.secondarycategoryid;
                        }
                        break;
                    }
                }
            },
            //三级
            thirdchange() {
                for (
                    var i = 0;
                    i < this.busCommodityThirdCategoryList.length;
                    i++
                ) {
                    if (
                        this.busCommodityThirdCategoryList[i].thirdcategoryid ===
                        this.formData.thirdcategoryid
                    ) {
                        this.formData.categorylevl = 3;
                        this.formData.categoryid = this.formData.thirdcategoryid;
                    }
                }
            },
            //获得分类
            getAllCategory() {
                //this.loading = true;
                getCategory()
                    .then(response => {
                        if (response.code) {
                            this.$message.error(response.message);
                        }
                        let data = response.data || [];
                        //一级
                        if (data) {
                            for (let i = 0; i < data.length; i++) {
                                data[i].topcategoryid = data[
                                    i
                                    ].topcategoryid.toString();
                                let sec = data[i].busCommoditySecondaryCategoryList;
                                //二级
                                if (sec) {
                                    for (let j = 0; j < sec.length; j++) {
                                        sec[j].secondarycategoryid = sec[
                                            j
                                            ].secondarycategoryid.toString();
                                        let thr =
                                            sec[j].busCommodityThirdCategoryList;
                                        //三级
                                        if (thr) {
                                            for (let t = 0; t < thr.length; t++) {
                                                thr[t].thirdcategoryid = thr[
                                                    t
                                                    ].thirdcategoryid.toString();
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        this.category = data;
                        setTimeout(() => {
                            this.loading = false;
                        }, 0.3 * 1000);
                    })
                    .catch(() => {
                        // this.loading = false;
                    });
            },
            // 隐藏表单
            hideForm() {
                // 更改值
                this.formVisible = !this.formVisible;
                // 清空表单
                this.$refs["dataForm"].resetFields();

                this.query.warehousename = "";
                return true;
            },
            // 显示表单
            handleForm(index, row) {
                this.formVisible = true;
                this.formData = Object.assign({}, formJson);
                this.createTime = [];
                if (row !== null) {
                    this.formData = Object.assign({}, row);
                    this.commodityname = row.commodityname;
                    /* this.createTime.push()new Date(), new Date()*/
                    this.createTime.push(new Date(this.formData.takeeffecttime));
                    this.createTime.push(new Date(this.formData.invalidtime));
                    // alert(this.createTime)
                    if (row.bannejumptype === "2") {
                        this.getAllCategory();
                    }

                    let data = {
                        name: "",
                        url: ""
                    };
                    if (row.bannepicture) {
                        this.uploadData = [];
                        let nameurl = row.bannepicture;
                        data.url = nameurl;
                        data.name = nameurl.substring(nameurl.lastIndexOf("/") + 1);
                        this.uploadData.push(data);
                    }
                }
                this.formName = "add";
                //编辑
                if (index !== null) {
                    this.index = index;
                    this.formName = "edit";
                    this.editshow = true;
                } else {
                    this.editshow = false;
                    // 清空验证信息表单
                    if (this.$refs["dataForm"]) {
                        this.$refs["dataForm"].clearValidate();
                    }
                }
            },

            //显示 查看弹框
            detailForm(index, row) {
                if (row !== null) {
                    this.detailVisible = true;
                    this.formData = Object.assign({}, row);
                    this.formName = "detail";
                }
            },

            formSubmit() {
                this.$refs["dataForm"].validate(valid => {
                    if (valid) {
                        this.formLoading = true;
                        if (!this.formData.commodityid) {
                            this.formData.commodityid = 0;
                        }
                        if (!this.formData.categoryid) {
                            this.formData.categoryid = 0;
                        }
                        let data = new URLSearchParams(this.formData);
                        console.info(this.formData);
                        if (this.editshow) {
                            // console.info("666666");
                            updateBusCommodityBanner(data)
                                .then(response => {
                                    this.formLoading = false;
                                    if (response.code) {
                                        this.$message.error(response.message);
                                        return false;
                                    }
                                    this.$message.success("操作成功");
                                    // 刷新表单
                                    //this.$refs["dataForm"].resetFields();
                                    //this.$refs.tinymce.clearContent();
                                    this.formVisible = false;
                                    this.query.warehousename = "";
                                    this.getList();
                                })
                                .catch(() => {
                                    this.formLoading = false;
                                    //this.list = [];
                                });
                        } else {
                            addRotaryPlanting(data).then(response => {
                                this.formLoading = false;
                                if (response.code) {
                                    this.$message.error(response.message);
                                    return false;
                                }
                                this.$message.success("操作成功");
                                // 刷新表单
                                //this.$refs["dataForm"].resetFields();
                                //this.$refs.tinymce.clearContent();

                                this.formVisible = false;
                                this.formData = {};
                                this.getList();
                            });
                        }
                    }
                });
            },
            // 删除
            handleDel(ids) {
                if (ids) {
                    this.$confirm("确认要删除吗?", "提示", {
                        type: "warning"
                    })
                        .then(() => {
                            this.loading = true;
                            var params = new URLSearchParams();
                            params.append("ids", ids);
                            delRotaryPlanting(params)
                                .then(response => {
                                    this.loading = false;
                                    if (response.code) {
                                        this.$message.error(response.message);
                                        return false;
                                    }
                                    this.$message.success("删除成功");
                                    // 刷新数据
                                    //this.list.splice(index, 1);
                                    this.getList();
                                })
                                .catch(() => {
                                    this.loading = false;
                                });
                        })
                        .catch(() => {});
                }
            }
        },

        mounted() {},
        created() {
            // 将参数拷贝进查询对象
            let query = this.$route.query;
            this.query = Object.assign(this.query, query);
            this.query.pageSize = parseInt(this.query.pageSize);
            // 加载表格数据
            this.getList();
        }
    };
</script>

<style type="text/scss" lang="scss">
    body {
        margin: 0;
    }
</style>
